# 写函数，计算传⼊的字符串中数字，字⺟，空格，以及其他的个数
def count(string):
    str_list = list(string)
    number_num = 0
    alpha_num = 0
    space_num = 0
    other_num = 0
    for i in str_list:
        if type(i) == int:
            number_num += 1
        elif i.isalpha():
            alpha_num += 1
        elif i == " ":
            space_num += 1
        else:
            other_num += 1
    info = {"数字个数":number_num,"字母个数":alpha_num,"空格个数":space_num,"其他个数":other_num}
    return info

# print(count("Hello world!"))



# 写函数，判断⽤⼾传⼊的对象（字符串，列表，元组）⻓度是否⼤于5
def write_func(a):
    return len(a) > 5
# print(write_func((1,2,3,["sd",'sdsa','sdsd'])))

# 写函数监测⽤⼾传⼊的对象（字符，列表，元组）的每⼀个元素是否有空内容
def recv_space(a):
    flag = False
    for i in a:
        if i.isspace():
            flag = True
    boolin = ''
    if flag == True:
        boolin = "有空格"
    else:
        boolin = "没空格"
    return boolin
a = ('dasdsd dasd','ds')
res = recv_space(a)
# print(res)

# 写函数，检查传⼊列表的⻓度，如果⼤于2，那么仅仅保留前两个⻓度的内容，并将新内容返回给调⽤者
def func(l):
    if len(l) > 2:
        new_list = l[0:2]
    return new_list
res = func([12,12,45,78,32,12])
# print(res)


# 写函数，检查获取传⼊列表或元组的所有奇数位索引对应的元素，并将其作为新列表返回给调⽤者
def func1(l):
     num_list = []
     for i in range(len(l)):
         if i % 2 == 1:
             num_list.append(l[i])
     return num_list

res = func1([1,2,3,4,5,6,7,8,9])
print(res)



# 写函数，计算传⼊字符串中的【数字】、【字⺟】、【空格】和【其他】的个数
